package com.server.service.impl;


import com.server.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.MailException;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

@Service
public class MailServiceImpl implements MailService {

	@Autowired
	private JavaMailSender mailSender;

	@Override
	public void sendSimpleMail(String to, String subject, String body) {
		try {
			// 创建邮件对象
			SimpleMailMessage message = new SimpleMailMessage();
			message.setTo(to);
			message.setSubject(subject);
			message.setText(body);
			message.setFrom("");  // 设置发件人

			// 发送邮件
			mailSender.send(message);
		} catch (MailException e) {
			// 这里可以捕获邮件发送的异常并记录日志
			e.printStackTrace();
			throw new RuntimeException("邮件发送失败", e);
		}
	}


}